package com.borrowed.book.book.controller;

import com.borrowed.book.book.domain.SGroup;
import com.borrowed.book.book.domain.SLabel;
import com.borrowed.book.book.service.SBookService;
import com.borrowed.book.system.controller.BaseController;
import com.borrowed.book.system.domain.AjaxResult;
import com.borrowed.book.system.domain.BaseSelectPagePojo;
import com.borrowed.book.system.domain.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags="图书标签管理")
@RestController
@RequestMapping("/api/label")
public class BookLabelController extends BaseController {
    @Autowired
    private SBookService bookService;

    @ApiOperation(value = "标签添加",httpMethod = "POST")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult AddBookLabel(@RequestBody SLabel label){
        bookService.insertLabel(label);
        return AjaxResult.sucess();
    }


    @ApiOperation(value = "标签删除",httpMethod = "DELETE")
    @ApiImplicitParam(name="id",value = "1",type = "Long",required = true)
    @DeleteMapping("/delete")
    @Transactional
    @ResponseBody
    public AjaxResult DeleteBookLabel(Long  id){
        AjaxResult result=bookService.deleteBookLabelRel(id);
        return result;
    }

    @ApiOperation(value = "标签一览",notes = "支持分页查询，第几页：page,每页数量：limit",httpMethod = "GET")
    @GetMapping("/get")
    @ResponseBody
    public TableDataInfo SelectBookLabel(BaseSelectPagePojo pagePojo){
        startPage();
        List<SLabel> labelList=bookService.selectLabelList();
        return getDataTable(labelList);
    }



}
